<?php

namespace App\Http\Controllers\WeChat;

use App\Http\Controllers\Controller;
use App\Models\Site;
use App\Models\WeChat;
use Houdunren\WeChat\Button;
use Illuminate\Http\Request;

class MenuController extends Controller
{
    //需要的数据可以通过路由参数传递
    public function edit(Request $request, Site $site, WeChat $wechat)
    {
        return view('wechat.menu.edit', compact('site', 'wechat'));
    }

    public function update(Request $request, Site $site, WeChat $wechat)
    {


        $wechat->menus = $request->input('button');
        $wechat->save();
        return response()->json(['message' => '菜单添加成功']);
    }

    public function show(Site $site,WeChat $wechat)
    {

        return $wechat->menus;
    }

    public function push(Request $request, Site $site, WeChat $wechat, Button $button)
    {
//向微信推送时，存储微信的配置项
        config(['houdunren.wechat' => $wechat]);

        $button->create(['button' => $wechat->menus]);
        return response()->json(['message' => '微信菜单推送成功']);
    }
}
